<?php
class LoginAction extends Action {
   //登录
	public function index() {
		if($this->isPost()) {
			$this->_login()?$this->success('登录成功！', U('Index/index')):$this->error('登录失败！');
		} else {
			$this->assign('isLogin', false);
			$this->display();
		}
	}
	
	//登出
	public function logout() {
		setcookie('token', 0, time()-1, '/');
		$this->redirect('index');
	}
	
	//处理登录
	private function _login(){
		if ( !isset($this->users[ $_POST['account'] ]) ) {
			return false;
		} else {
			$passwd = $this->users[ $_POST['account'] ];
		}

		if( md5($_POST['password']) == $passwd ) {
			$uniqd = md5(time().rand(100,999));
			setcookie('token', $uniqd, 0, '/');
			$_SESSION['token'] = $uniqd;
			$_SESSION['account'] = $_POST['account'];
			return true;
		} else {
			return false;
		}
	}
    
    private $users = array(
        // 用户名 => MD5处理后的密码
        'szk' => '4d196db93f11b4a88499ae75a20c7edb',	//65983515
        'jwc' => '1d2caf142e87bf1c07f96191d8bf71f3',	//T7JxbN
        'cbs' => '70e98cd3584277e919225baf147fd6f4',	//H43llO
        'jiangdan' => '715eb11f5ef9434a6e2da09e8b869637',	//3D3D018
        'hekai' => 'e6394315bdab2a57a0302ea26cd920c3',
    );
}